#!/bin/bash

software_dir="comfyUI"
venv_name="amd${software_dir}"
RUN_SCRIPT="run_${software_dir}.sh"

#下载文件
[ ! -d "$software_dir" ] && git clone https://github.com/comfyanonymous/ComfyUI.git $software_dir
cd $software_dir
[ ! -d "$venv_name" ] && python3 -m venv $venv_name
source $venv_name/bin/activate

pip3 install -r requirements.txt
pip3 uninstall -r torch torchvision
pip3 install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/rocm6.0
#pip install torch==2.2.2 torchvision==0.17.2 torchaudio==2.2.2 --index-url https://download.pytorch.org/whl/rocm5.7
#pip install torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 --index-url https://download.pytorch.org/whl/rocm5.4.2

cd custom_nodes
git clone https://github.com/ltdrdata/ComfyUI-Manager.git
cd ..


echo "建立启动脚本"
if [ ! -f "$RUN_SCRIPT" ]; then
    cat > $RUN_SCRIPT <<EOF
#!/bin/bash
source $venv_name/bin/activate
python main.py
EOF
    chmod +x $RUN_SCRIPT
fi

echo "安装完成"
